package com.yanqu.road.server.logic.activity.condition.tomb;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;
import java.util.Map;

public class TombUnionNianTuCondition extends BaseActivityCondition {
    public TombUnionNianTuCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    /**
     * 客户端写死 数值说运营会配错 所以用的百分比
     */
    @Override
    protected void player_BoardLevelHandle(Object object) {
        Map<Integer,Long> args = (Map<Integer,Long>) object;
        if (null == args){
            return;
        }
        if (args.isEmpty()){
            return;
        }
        for (Map.Entry<Integer,Long> entry:args.entrySet()){
            if (entry.getKey().equals(activityConditionInfo.getParamList().get(2).intValue())){//增加对应区域的进度
                BigInteger nianTuNum = BigInteger.valueOf(entry.getValue());
                if (nianTuNum.compareTo(getValue()) > 0) {
                    setValue(nianTuNum);
                }
            }
        }


    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.TombUnionNianTuNum.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.TombUnionNianTuNum.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }



}
